<?php

class LancamentoService extends Model {

    /**
     * @var LancamentoDao
     */
    private $lancamentoDao;
    /**
     * @var ConfirmacaoService
     */
    private $confirmacaoService;

    public function injectDependencies() {
        $this->lancamentoDao = LancamentoDao::getInstance();
        $this->confirmacaoService = ConfirmacaoService::getInstance();
    }

    public function findByCustomer($IDCustomer) {
        $ArReleases = $this->lancamentoDao->findReleasesByCustomer($IDCustomer);
        $this->fillRelease($ArReleases);
        return $ArReleases;
    }

    public function findById($IDPayment) {
        $Release = $this->lancamentoDao->findById($IDPayment);
        return $Release;
    }

    private function fillRelease(&$MxRelease) {
        if (!empty($MxRelease)) {
            $this->fillReleaseWithConfirmation($MxRelease);
        }
    }

    private function fillReleaseWithConfirmation(&$MxRelease) {
        if (!is_array($MxRelease)) {
            $MxRelease->setConfirmacao($this->confirmacaoService->findByRelease($MxRelease->getIDDebito()));
            return;
        }
        foreach ($MxRelease as &$Release) {
             $Release->setConfirmacao($this->confirmacaoService->findByRelease($Release->getIDDebito()));
        }
    }

}

?>
